var mainModule = angular.module("mainModule", []);

mainModule.controller('mainCtrl', ['$scope', '$http', '$state', '$stateParams', 
                                   function($scope, $http, $state, $stateParams  ) {

       $scope.login=function(){
            layer.msg('加载中', {icon: 16});
         
            $http.post("/login",{username:$scope.username,pwd:$scope.pwd,door:$scope.door})
 				.success(function(data, status, headers, config) {
                    layer.closeAll('loading');
  					if(data.code==200){
  						 $state.go('list');
  					}
            if(data.code==444){
                  layer.msg('需要验证码');
                  $scope.checkImg=data.data;
            }
  					else{
  						  layer.msg('用户名或密码错误');
  					}
 				});
       }

}]);
 


mainModule.controller('listCtrl', ['$rootScope', '$scope', '$http', '$state', '$stateParams', 
                                   function($rootScope, $scope, $http, $state, $stateParams  ) {
      
        layer.msg('加载中', {icon: 16});
          
         $http.post("/list",{username:$scope.username,pwd:$scope.pwd})
 				.success(function(data, status ) {
  						layer.closeAll('loading');
  					if(data.code==200){
  						 $scope.list= data.data.list;
  						 $scope.lotteryList = data.data.lotteryList;
  					}else{
  						 $state.go('main');
  					}
 				});


      $scope.lottery=function(s){
                layer.msg('加载中', {icon: 16});
          
      	        $http.post("/lottery",{id:s.id,count:s.count,followMe:s.followMe})
      					.success(function(data) {
      	 				 
      	 				 layer.closeAll('loading');
      	 					if(data.code==200){
                               $rootScope.rst = data.data.list;
                               $state.go('lottery');
      	 					}
      	 					else{
      	 					 $state.go('main');
      	 					}
      					});


      }

 
	

}]);
 
	


mainModule.controller('lotteryCtrl', ['$rootScope', '$scope', '$http', '$state', '$stateParams', 
                                   function($rootScope, $scope, $http, $state, $stateParams  ) {

         


      
 

}]);
 
